package entity

import (
	"fmt"
	"time"

	"gorm.io/gorm"

	"shqsoft.cn/pas3ui/base"
)

//Fxgll
type Fxgll struct {
	ID        int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	DPID      int       `gorm:"column:DPID"`
	DPNM      string    `gorm:"column:DPNM"`
	DFJD      time.Time `gorm:"column:DFJD"`
	ZBID      int       `gorm:"column:ZBID"`
	ZBNM      string    `gorm:"column:ZBNM"`
	BM_211127 string    `gorm:"column:BM_211127"`
	BM_211131 string    `gorm:"column:BM_211131"`
	BM_211124 string    `gorm:"column:BM_211124"`
	BM_211122 string    `gorm:"column:BM_211122"`
	BM_211123 string    `gorm:"column:BM_211123"`
	BM_211125 string    `gorm:"column:BM_211125"`
	BM_211126 string    `gorm:"column:BM_211126"`
	BM_221653 string    `gorm:"column:BM_221653"`
	BM_221654 string    `gorm:"column:BM_221654"`
	BM_221655 string    `gorm:"column:BM_221655"`
	SJBM      string    `gorm:"column:SJBM"`
	FZQJ      string    `gorm:"column:FZQJ"`
	JBF       string    `gorm:"column:JBF"`
}

//TableName
func (Fxgll) TableName() string {
	return "SH_JHCW_FXGL"
}

func (s *Fxgll) BeforeSave(tx *gorm.DB) (err error) {
	jdint := datenfjj(s.DFJD)
	err = can_import(tx, jdint)
	if err != nil {
		return
	}
	var emid *int
	tx.Raw(`select "ZBID" from "SH_JHCW_FXGL_BM_PERM" where "ZBMC" = ?`, s.ZBNM).Row().Scan(&emid)
	if emid == nil {
		err = fmt.Errorf("指标%s在系统中不存在！", s.ZBNM)
		return
	}
	s.ZBID = *emid
	tx.Raw(`SELECT "BMMC" FROM "SH_JHCW_FXGL_PERM" WHERE "BMID"=?`, s.DPID).Row().Scan(&s.DPNM)
	return
}

func FxgllEF() base.EntityFunc {
	return func() interface{} {
		entity := Fxgll{}
		return &entity
	}
}
func FxgllESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []Fxgll
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("Fxgll", base.NewDefaultDao(FxgllEF(), FxgllESF(), nil, "my"))
}
